package com.niuniu.rushdorm.config;

/**
 * @author Meng
 */

import com.niuniu.rushdorm.filter.AuthFilter;
import com.niuniu.rushdorm.filter.ExceptionHandlerFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FilterConfig {
    @Autowired
    ExceptionHandlerFilter exceptionHandlerFilter;
    @Autowired
    AuthFilter authFilter;
    @Bean
    public FilterRegistrationBean registerExceptionHandlerFilter(){
        FilterRegistrationBean registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(exceptionHandlerFilter);
        registrationBean.addUrlPatterns("/*");
        registrationBean.setOrder(0);
        return registrationBean;
    }
    @Bean
    public FilterRegistrationBean registerAuthFilter(){
        FilterRegistrationBean registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(authFilter);
        registrationBean.addUrlPatterns("/*");
        registrationBean.setOrder(100);
        return registrationBean;
    }
}
